import java.util.*;

/**
 * @author LKQ
 * @date 2022/6/6 22:08
 * @description 二分查找，f(x)为 <= x的神奇数字的个数，那么f(x)为单调递增函数，可以采用二分查找
 */
public class Solution {
    public static void main(String[] args) {
        System.out.println(Long.MAX_VALUE);
        System.out.println((long) 1e15);
    }
    public int nthMagicalNumber(int n, int a, int b) {
        long lo = 0, hi = (long) 1e15;
        int MOD = (int) 1e9 + 7;
        // 最小公倍数
        long L = (long) a * b / gcd(a, b);
        // f(x) = x / a + x / b - x / L, 解释；x / a个数字能被 a整除， x / b个数字能被 b整除，但是中间多统计了一次最小公倍数的整数倍数字;
        while (lo < hi) {
            long mid = (lo + hi) / 2;
            if (mid / a + mid / b - mid / L < n ) {
                lo = mid + 1;
            }else {
                hi = mid;
            }
        }
        return (int) (lo % MOD);
    }

    public int gcd(int a, int b) {
        return b != 0 ? gcd(b, a % b) : a;
    }
}
